package com.henu.service;

import java.util.List;

import org.smart4j.framework.dao.DataSet;
import org.smart4j.framework.dao.DatabaseHelper;
import org.smart4j.framework.tx.annotation.Service;

import com.henu.model.Category;

@Service
public class CategoryService {

    public List<Category> getCategorys() {
        return DataSet.selectList(Category.class, "", "");
    }
    public int insertCategory(String categoryName, String categoryContent, String imageUrl) {
        String sql = "insert into category(imageUri,categoryName,categoryContent) values(?,?,?)";
        return DatabaseHelper.update(sql, imageUrl, categoryName, categoryContent);
    }

    public int deleteCategoryByID(Integer id) {
        String sql = "delete from category t where t.id=?";
        return DatabaseHelper.update(sql, id);
    }
    public int updateCategory(Integer id, String categoryName, String categoryContent, String imageUrl) {
        String sql = "update category t set t.imageUri=?,t.categoryName=?,t.categoryContent=? where t.id=?";
        return DatabaseHelper.update(sql, imageUrl, categoryName, categoryContent, id);
    }
}
